#include "pr/TrainingSetReader.h"
#include "util/Utility.h"

namespace pr {

TrainingSetReader::TrainingSetReader(TrainingSet& trainingSet)
  : trainingSet_(trainingSet)
{
}

void TrainingSetReader::readConfigFromFile(const std::string& configFilename)
{
  std::ifstream is(configFilename.c_str());
  std::string str;
  while (std::getline(is, str).good()) {
    std::size_t pos = str.find_first_of(' ');
    if (pos != std::string::npos)
    {
      config_.addPattern(str.substr(0, pos),
              util::Utility::fromString<std::size_t>(str.substr(pos+1)),
              "");
    }
  }
  is.close();
}

void TrainingSetReader::addPattern(const std::string& url, std::size_t classId, const std::string& resourceType)
{
  config_.addPattern(url, classId, resourceType);
}


} // namespace pr
